package com.hhit.brpc.controller;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baidu.brpc.spring.annotation.RpcProxy;
import com.hh.analyse.Analyse.AnalyseImageInfo;
import com.hh.analyse.Analyse.AnalyseImageResponse;
import com.hh.analyse.service.CommonService;
import com.hhit.brpc.service.BrpcCommonService;

@RestController
public class RpcClientController {
	@Autowired
	private BrpcCommonService brpcCommonService;
	@RpcProxy
	private CommonService commonService;
	
	/**
	 * 异步
	 * @return
	 */
	@RequestMapping("/")
	public String test() {
		AnalyseImageInfo request = AnalyseImageInfo.newBuilder().setClientId("test1").setImageId("hhit_" + System.currentTimeMillis()).build();
		Future<AnalyseImageResponse> future = brpcCommonService.pushAnalyseImage(request);
		try {
			future.get();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
		return "success";
	}
	
	/**
	 * 同步
	 * @return
	 */
	@RequestMapping("test2")
	public String test2() {
		AnalyseImageInfo request = AnalyseImageInfo.newBuilder().setClientId("test2").setImageId("hhit_" + System.currentTimeMillis()).build();
		commonService.pushAnalyseImage(request);
		return "success";
	}
}
